package org.openharmony.qttool;

import com.intellij.ui.table.JBTable;

import javax.swing.table.TableColumn;

public class QtSDKTable extends JBTable {
    public QtSDKTable() {
        super(new QtSDKTableModel());

        resizeColumnWidth();
    }

    public void resizeColumnWidth() {
        TableColumn column = getColumnModel().getColumn(0);
        column.setPreferredWidth(50);
        getColumnModel().getColumn(1).setPreferredWidth(50);
        getColumnModel().getColumn(2).setPreferredWidth(300);
        setAutoResizeMode(JBTable.AUTO_RESIZE_LAST_COLUMN);
    }

    public boolean addSDK(String sdkPath) {
        QtSDKTableModel model = (QtSDKTableModel) getModel();
        if (model == null)
            return false;
        boolean result = model.add(sdkPath);
        if (result)
            updateUI();
        return result;
    }

    public String errorString() {
        QtSDKTableModel model = (QtSDKTableModel) getModel();
        if (model == null)
            return "";
        return model.errorString();
    }

    public void removeSDK(int index) {
        QtSDKTableModel model = (QtSDKTableModel) getModel();
        if (model == null)
            return;
        model.remove(index);
        updateUI();
    }
}
